Latest update: September 2018
In this tutorial, you will learn how to control FlashAir by using the iSDIO driver API on a RaspberryPi and set the Internet Pass-Thru Mode.
HW:Raspberry Pi 3 Model B + microSD->SDconversion adapter
OS:Raspbian (NOOBS ver.2.4.3)
NW:Access point with Internet connection
Using the microSD conversion adapter, connect FlashAir to the microSD slot of Raspberry Pi 3 as shown above.
APPMODE=0
in the CONFIG file of the SD_WLAN folder.
iSDIO_tutorial_sample
|-inc folder (iSDIO driver API header section)
| |- isdio_api.h
| |- isdio_wlan_api.h
| |- isdioreg.h
| └─ mmc.h
|
|-sample folder
| |- iSDIO_tutorial_sample.c (This tutorial sample code)
| └─ Makefile
|
└─src folder (iSDIO driver API source section)
|- isdio_api.c
|- isdio_wlan_api.c
└─ isdioreg.c
isdio_sample
will be created.
> sudo ./isdio_sample
I will explain the downloaded sample code (iSDIO_tutorial_sample.c).
Initialize iSDIO card control information to use FlashAir.
iSDIO_INFO_t *s_info; /* iSDIO card control information pointer */
char *s_device = "/dev/mmcblk0" ; /* SD card device information */
/* iSDIO initialization */
s_info = iSDIO_Init(s_device);
printf(" info=0x%p\n", s_info);
if (s_info != NULL) {
printf("info->fno=%d\n", s_info->fno);
system("mount /dev/mmcblk0p1 /mnt");
Search for access points that FlashAir can recognize.
/* Acquire information on surrounding access points */
result = iSDIO_WLAN_Scan(s_info, s_seq_id ++);
if (result == E_iSDIO_OK) {
/* Wait for completion of the iSDIO command execution process */
timeout = 20000; /* Scan's timeout is 20 seconds, so 20000 ms */
cmd_success = FALSE;
/* Wait for WLAN_Scan response */
cmd_success = response_wait(s_info, (s_seq_id-1), iSDIO_WLAN_SCAN, timeout);
if (cmd_success == FALSE) {
printf("WLAN_Scan response error !!!\n");
}
else {
-1
from the current sequence ID to set the sequence ID when iSDIO_WLAN_Scan command is
executed.
Set yourself as an access point while connecting to the Internet using FlashAir.
uint8_t apssid[32] = "myflashair"; /* FlashAir (AP side) Wireless LAN SSID */
uint8_t apnetworkKey[64] = "password0123"; /* FlashAir (AP side) Wireless LAN network key */
uint8_t brgssid[32] = "LANSSID"; /* Internet (STA side) Wireless LAN SSID */
uint8_t brgnetworkKey[64] = "lanpassword0123"; /* Internet (STA side) Wireless LAN network key */
uint32_t encMode = iSDIO_WLAN_ENCMODE_WPA2_PSK_AND_AES; /* Operating mode = 6 */
/* When there is an access point around */
/* Acquire the access point name to determine whether there is a target STA */
for(lp=0;lp<num;lp++) {
memset(getssid,0x00,32); /* Access point name acquisition buffer clear */
/* Acquire access point name with specified number */
result = iSDIO_WLAN_GetSSID(s_info, lp , getssid);
if(result != E_iSDIO_OK) {
printf("WLAN_GetSSID get error !!!\n");
exit(0);
}
printf("SSID#%d SSID=%s\n",lp, getssid);
if(strstr((const char *)getssid, (const char *)brgssid)) {
/* Bridge setting with target STA*/
result = iSDIO_WLAN_Bridge(s_info, s_seq_id++,
apssid, sizeof(apssid),
apnetworkKey, sizeof(apnetworkKey),
encMode,
brgssid, sizeof(brgssid),
brgnetworkKey, sizeof(brgnetworkKey));
if(result != E_iSDIO_OK) {
printf("Bridge Set error!!!\n");
exit(0);
}
break;
}
}
iSDIO_WLAN_Bridge does not work unless FlashAir is in disconnected state.
If FlashAir is already
connected to another device, execute iSDIO_WLAN_Disconnect first.
If you want to know the connection
status, when iSDIO_WLAN_Check_WLANConnect is executed, the connection status is output to the argument
connect.
We will explain response wait processing waiting for the result of asynchronous command.
/* Sample function waiting for command response */
bool_t response_wait(iSDIO_INFO_t *s_info, uint32_t seq_id, uint32_t cmd_id, int32_t timeout)
{
iSDIO_CommandResponseStatus_t *status;
int32_t timeout_cnt = timeout / 10; // ms / 10
bool_t cmd_success = FALSE;
/* Loop until the command response status exits from running or it times out */
do {
status = iSDIO_ReadCommandResponseStatus(s_info);
if ((status->response_status != iSDIO_COMMAND_PROCESSING) && (status->cmd_id==cmd_id)) {
if (status->response_status == iSDIO_PROCESS_SUCCEEDED) {
cmd_success = TRUE;
}
break;
printf("res_wait=%d\n",status->response_status);
}
sleep(10); // Wait 10ms
timeout_cnt --;
} while (timeout_cnt > 0);
return cmd_success;
}
Let's run it.
> sudo ./isdio_sample
dev/mmcblk0 open success
info=0x27268
info->fno=1
SSID#1 SSID=LANSSID
WLAN_Bridge set success
WLAN_BridgeGetInfoByRegister get response success
http://flashair/
by connecting to the SSID
"myflashair" from a PC / smartphone etc. not connected to the Internet.The asynchronous commands are as follows.
Synchronous commands are as follows.
iSDIO_tutorial_sample.zip (24KB)